#include "HoursMinutesSeconds.h"
#include <ctime>
#include <sstream>

HoursMinutesSeconds::HoursMinutesSeconds(long seconds) {
    this->seconds = seconds % 60;
    this->minutes = seconds / 60;
    this->hours = minutes / 60;
    this->minutes = minutes % 60;
}

HoursMinutesSeconds::~HoursMinutesSeconds() {
}

string HoursMinutesSeconds::toString() const {
    ostringstream oss;
    if (hours) oss << hours << "h";
    if (hours && minutes) oss << " ";
    if (minutes) oss << minutes << "m";
    if (hours || minutes && seconds) oss << " ";
    if (seconds) oss << seconds << "s";
    if (!hours && !minutes && !seconds) oss << "0s";
    return oss.str();
}

ostream& operator<<(ostream& os, const HoursMinutesSeconds& hms) {
    os << hms.toString();
    return os;
}
